package com.yx1996.management.ExcelUtils;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.yx1996.management.Bean.User;
import org.springframework.stereotype.Component;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

@Component
public class WriteExcel2003 {

    public boolean writeFile(String filepath, List<User> userp) throws IOException {
        final List<User> usero = ReadExcel2003.readFile(filepath);
        usero.addAll(userp);
        OutputStream out = new FileOutputStream(filepath);
        ExcelWriter writer = EasyExcelFactory.getWriter(out, ExcelTypeEnum.XLS, true);

        Sheet sheet = new Sheet(1, 1, User.class);
        writer.write(usero, sheet);
        writer.finish();
        out.close();
        return true;
    }
}
